﻿using Fabrication.Tests.TestClasses;
using NUnit.Framework;

namespace Fabrication.Tests
{
    [TestFixture]
    public class scope_usage
    {
        [Test]
        public void should_generate_single_instance_inline_with_no_setup()
        {
            var builtItem = new FabricationScope().Generate<SinglePropertyClass<string>>();

            Assert.That(builtItem, Is.Not.Null);
        }

        [Test]
        public void should_generate_multiple_instances_inline_with_no_setup()
        {
            var builtItems = new FabricationScope().Generate<SinglePropertyClass<string>>(10);

            Assert.That(builtItems, Has.Count.EqualTo(10));
            Assert.That(builtItems, Has.All.Not.Null);
        }
        
        [Test]
        public void should_generate_single_instance_inline_with_setup()
        {
            var builtItem = new FabricationScope().Setup<SinglePropertyClass<string>>()
                                                  .Generate();

            Assert.That(builtItem, Is.Not.Null);
        }

        [Test]
        public void should_generate_multiple_instances_inline_with_setup()
        {
            var builtItems = new FabricationScope().Setup<SinglePropertyClass<string>>()
                                                   .Generate(10);

            Assert.That(builtItems, Has.Count.EqualTo(10));
            Assert.That(builtItems, Has.All.Not.Null);
        }

        [Test]
        public void should_handle_rules_for_different_types_with_same_property_name()
        {
            var scope = new FabricationScope();
            scope.Setup<SinglePropertyClass<string>>()
                .For(x => x.Value).Use("Scope1Value");

            Assert.DoesNotThrow(() => scope.Setup<SinglePropertyClass<int>>().For(x => x.Value).Use(23));
        }
    }
}
